//角色管理模块的的接口
import { post, get, deleteR, patch } from "@/http/request";
import type { RoleData, DeletResponse, MenuList } from "./type";
import type { ApiResponse } from "@/api";

//新增或更新角色信息
export const reqAddOrUpdateRole = (data: RoleData) => {
	if (data.id) {
		return patch<ApiResponse<RoleData>, RoleData>({}, `/role/${data.id}`, data);
	} else {
		return post<ApiResponse<RoleData>, RoleData>({}, "/role", data);
	}
};

//获取全部的角色列表数据
export const reqAllRoleList = async (params: any) => {
	return get<any>({}, "/role", params);
};

//删除已有的角色
export const reqRemoveRole = async (id: number) => {
	return deleteR<ApiResponse<DeletResponse>>({}, `/role/${id}`);
};

//分配权限给角色后的树形结构数据
export const reqAllMenuList = async (id: number) => {
	return get<ApiResponse<{ menu: MenuList; checkedKeys: number[] }>>({}, `/role/${id}/roleMenuTreeselect`);
};

export const reqSetPermisstion = async (id: number, data: any) => {
	return patch<any>({}, `/role/${id}/doAssign`, data);
};

export const reqGetRoleList = async () => {
	return get<any>({}, "/role/options");
};
